package com.hjl.service.impl;

import com.hjl.dao.DocumentDao;
import com.hjl.dao.impl.DocumentDaoImpl;
import com.hjl.domain.Doc_User_inf;
import com.hjl.domain.Document_inf;
import com.hjl.domain.PageBean;
import com.hjl.service.DocumentService;
import java.util.List;
import java.util.Map;

/**
 * 文件业务逻辑层实现类
 *
 * @author Lenovo
 * @version 1.0
 * @date 2021/10/8 20:35
 */
public class DocumentServiceImpl implements DocumentService {
    private DocumentDao documentDao = new DocumentDaoImpl();

    /**
     * 分页查询
     *
     * @param currentPageString 当前页
     * @param rowsString        行数
     * @param condition         状态
     * @return com.hjl.domain.PageBean<com.hjl.domain.Doc_User_inf>
     * @author Lenovo
     * @date 2021/10/8 20:39
     */
    @Override
    public PageBean<Doc_User_inf> findDocumentByPage(String currentPageString, String rowsString, Map<String, String[]> condition) {
        int currentPage = Integer.parseInt(currentPageString);
        int rows = Integer.parseInt(rowsString);
        int totalCount = documentDao.findTotalCount(condition);
        int start = (currentPage - 1) * rows;
        List<Doc_User_inf> list = documentDao.findByPage(start, rows, condition);
        int totalPage = totalCount % rows == 0 ? totalCount / rows : (totalCount / rows + 1);

        //创建PageBean并放入数据，返回
        return new PageBean<>(totalCount, totalPage, list, currentPage, rows);
    }

    /**
     * 删除选中
     *
     * @param ids 选中的id
     * @author Lenovo
     * @date 2021/10/8 20:40
     */
    @Override
    public void delSelect(String[] ids) {
        if (ids != null && ids.length > 0) {
            for (String id : ids) {
                documentDao.delDocument(Integer.parseInt(id));
            }
        }
    }

    /**
     * /通过id查询
     *
     * @param id ID
     * @return com.hjl.domain.Document_inf
     * @author Lenovo
     * @date 2021/10/8 20:40
     */
    @Override
    public Document_inf findDocumentById(String id) {
        return documentDao.findDocumentById(Integer.parseInt(id));
    }

    /**
     * 更新
     *
     * @param document 文件对象
     * @author Lenovo
     * @date 2021/10/8 20:40
     */
    @Override
    public void updateDocument(Document_inf document) {
        documentDao.updateDocument(document);
    }

    /**
     * 添加
     *
     * @param document 文件对象
     * @author Lenovo
     * @date 2021/10/8 20:40
     */
    @Override
    public void addDocument(Document_inf document) {
        documentDao.addDocument(document);
    }

    /**
     * 更新（不更改文件）
     *
     * @param document 文件对象
     * @author Lenovo
     * @date 2021/10/8 20:40
     */
    @Override
    public void updateWithoutDocument(Document_inf document) {
        documentDao.updateWithoutDocument(document);
    }
}
